package com.fulihui.information.core.repository.impl;

import com.fulihui.information.core.repository.ContentCommentsRepository;
import com.fulihui.information.dal.dataobj.InfoContentComments;
import com.fulihui.information.dal.dataobj.InfoContentCommentsExample;
import com.fulihui.information.dal.mapper.ExtInfoContentCommentsMapper;
import com.fulihui.information.dal.mapper.InfoContentCommentsMapper;
import com.fulihui.information.dto.InfoContentCommentsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.fulihui.information.biz.conv.ContentCommentsConv.toDTO;
import static com.fulihui.information.biz.conv.ContentCommentsConv.toDTOList;

/**
 * Created by LM on 2017/4/9.
 */
@Repository
public class ContentCommentsRepositoryImpl implements ContentCommentsRepository {

    @Autowired
    private InfoContentCommentsMapper    commentsMapper;
    @Autowired
    private ExtInfoContentCommentsMapper extCommentsMapper;

    @Override
    public boolean create(InfoContentComments infoContentComments) {
        return commentsMapper.insertSelective(infoContentComments) > 0;
    }

    @Override
    public boolean update(InfoContentComments infoContentComments) {
        return commentsMapper.updateByPrimaryKeySelective(infoContentComments) > 0;
    }

    @Override
    public List<InfoContentCommentsDTO> queryPage(InfoContentCommentsExample example) {
        return toDTOList(commentsMapper.selectByExample(example));
    }

    @Override
    public long countByExample(InfoContentCommentsExample example) {
        return commentsMapper.countByExample(example);
    }

    @Override
    public boolean praiseTotalAdd(String commentsId) {
        return extCommentsMapper.praiseTotalAdd(commentsId);
    }

    @Override
    public boolean replyTotalAdd(String commentsId) {
        return extCommentsMapper.replyTotalAdd(commentsId);
    }

    @Override
    public InfoContentCommentsDTO selectByPrimaryKey(String id) {
        return toDTO(commentsMapper.selectByPrimaryKey(id));
    }

}
